//
//  GSecondViewItemView.m
//  helpinrain
//
//  Created by Gang.Wang on 12-7-26.
//  Copyright (c) 2012年 Zhuhai Yuike Technology Co., Ltd. All rights reserved.
//

#import "GSecondViewItemView.h"

#import "mcf.h"


@interface GSecondViewItemView ()
{
    UILabel * lable_;
    UIViewEx * contentView_;
}

@property (nonatomic, strong) UILabel * label;
@property (nonatomic, strong) UIViewEx * contentView;

- (void) privateInit;

@end


@implementation GSecondViewItemView

@synthesize delegate = delegate_;
@synthesize section = section_;

@synthesize label = lable_;
@synthesize contentView = contentView_;

- (void)dealloc
{
    YRelease(section_)
    YRelease(lable_)
    
    YRelease(contentView_)
    
    [super dealloc];
}


- (id) init
{
    self = [super init];
    if (self) 
    {
        [self privateInit];
    }
    
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self privateInit];
    }
    return self;
}

- (void) privateInit
{
    if (self.bInited) 
    {
        return;
    }
    
    [self setBackgroundColor:COLOR_CLEAR];
    
    UIViewEx * temp_contentView = [[UIViewEx alloc] init];
    [temp_contentView setBackgroundColor:COLOR_RANDOM];
    [[temp_contentView layer] setCornerRadius:isPad? 15 : 5];
    [temp_contentView setClipsToBounds:TRUE];
    self.contentView = temp_contentView;
    YRelease(temp_contentView)
    [self addSubview:self.contentView];
    
    UILabel * temp_label =[[UILabel alloc] init];
    [temp_label setBackgroundColor:COLOR_CLEAR];
    [temp_label setTextColor:COLOR_WHITE];
    [temp_label setTextAlignment:UITextAlignmentCenter];
    [temp_label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:isPad ? 30 : 16]];
    temp_label.lineBreakMode = UILineBreakModeCharacterWrap;     
    temp_label.numberOfLines = 0;    
    self.label = temp_label;
    YRelease(temp_label)
    [self.contentView addSubview:self.label];
    
    [self reAdjustLayout];
    self.bInited = TRUE;
}

- (void) setFrame:(CGRect)frame
{
    [super setFrame:frame];
    [self reAdjustLayout];
}

- (void) reAdjustLayout
{
    [self.contentView setFrame:CGRectMake(20, 20, self.width - 40, self.height - 40)];
    
    [self.label setFrame:self.contentView.bounds];
}


- (void) setSection:(GSection *)sectionValue
{
    YRelease(section_)
    section_ = [sectionValue retain];
    
    if (!sectionValue) 
    {
        return;
    }
    
    [self.label setText:sectionValue.name];
}


- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    DELEGATE_CALLBACK(openSection:, self.section)
}

@end
